import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import dts from "vite-plugin-dts";
import { resolve } from "path";
import styleImport from "vite-plugin-style-import";

export default defineConfig({
  plugins: [
    react({
      jsxRuntime: "automatic", // React 19 支持
    }),
    dts({
      include: ["src"],
      outDir: "dist",
      insertTypesEntry: true,
    }),
    styleImport({
      libs: [
        {
          libraryName: "antd",
          esModule: true,
          resolveStyle: (name) => `antd/es/${name}/style`,
        },
      ],
    }),
  ],
  build: {
    lib: {
      entry: resolve(__dirname, "src/index.ts"),
      name: "DbUiSimple",
      formats: ["es", "umd"],
      fileName: (format) => `index.${format}.js`,
    },
    rollupOptions: {
      external: ["react", "react-dom", "antd"],
      output: {
        globals: {
          react: "React",
          "react-dom": "ReactDOM",
          antd: "antd",
        },
        manualChunks: {
          "antd-components": ["antd"],
        },
      },
    },
    // 优化构建性能
    minify: "terser",
    terserOptions: {
      compress: {
        drop_console: true,
      },
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        modifyVars: {
          "@primary-color": "#1890ff", // 自定义主题
        },
      },
    },
  },
});
